package com.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import javax.sql.DataSource;
/*
等同于
<context:property-placeholder location="classpath*:jdbc.properties"/>
 */
@PropertySource("classpath:jdbc.properties")
public class jdbcConfig {
    public class J {
        @Value("${jdbc.driverClassName}")
        private String driver;
        @Value("${jdbc.url}")
        private String url;
        @Value("${jdbc.userName;}")
        private String userName;
        @Value("${jdbc.password}")
        private String password;
        @Bean("dateSource")
        public DataSource getDataSource(){
            DruidDataSource ds = new DruidDataSource();
            ds.setDriverClassName(driver);
            ds.setUrl(url);
            ds.setUsername(userName);
            ds.setPassword(password);
            return ds;
        }
    }
}
